﻿Public Class Character
    Private _name As String
    Private _npc As Boolean
    Private _speed As Double
    Private _endurance As Integer
    Private _recovery As Integer
    Private _body As Integer
    Private _stun As Integer
    Private _dexterity As Integer
    Private _phases As New List(Of Integer)
    Private _isacted As Boolean
    Private _dcv As Integer
    Private _ed As Integer
    Private _ego As Integer
    Private _md As Integer
    Private _mdcv As Integer
    Private _mocv As Integer
    Private _ocv As Integer
    Private _pd As Integer
    Private _red As Integer
    Private _rpd As Integer
    Private _powerd As Integer
    Private _currentstun As Integer
    Private _currentbody As Integer
    Private _currentendurance As Integer

    Public Event SpeedChanged(ByVal item As Character, ByVal newspeed As Double)
    Public Event EnduranceChanged(ByVal item As Character, ByVal newendurance As Integer)
    Public Event RecoveryChanged(ByVal item As Character, ByVal newrecovery As Integer)
    Public Event BodyChanged(ByVal item As Character, ByVal newbody As Integer)
    Public Event StunChanged(ByVal item As Character, ByVal newstun As Integer)
    Public Event DexterityChanged(ByVal item As Character, ByVal newdexterity As Integer)

    Public Sub New()
        Me.Name = ""
        Me.Body = 0
        Me.DCV = 0
        Me.Dexterity = 0
        Me.ED = 0
        Me.Ego = 0
        Me.IsActed = False
        Me.MD = 0
        Me.mDCV = 0
        Me.mOCV = 0
        Me.OCV = 0
        Me.PD = 0
        Me.rED = 0
        Me.rPD = 0
        Me.Endurance = 0
        Me.NPC = False
        Me.Recovery = 0
        Me.Speed = 0
        Me.Stun = 0
        Me.PowerDefense = 0
        Me.CurrentBody = 0
        Me.CurrentEndurance = 0
        Me.CurrentStun = 0
    End Sub

    Public Sub New(ByVal name As String)
        Me.New()
        Me.Name = name
    End Sub

    Public Property CurrentStun() As Integer
        Get
            Return _currentstun
        End Get
        Set(ByVal value As Integer)
            _currentstun = value
        End Set
    End Property

    Public Property CurrentBody() As Integer
        Get
            Return _currentbody
        End Get
        Set(ByVal value As Integer)
            _currentbody = value
        End Set
    End Property

    Public Property CurrentEndurance() As Integer
        Get
            Return _currentendurance
        End Get
        Set(ByVal value As Integer)
            _currentendurance = value
        End Set
    End Property

    Public Property PowerDefense() As Integer
        Get
            Return _powerd
        End Get
        Set(ByVal value As Integer)
            _powerd = value
        End Set
    End Property

    Public Property IsActed() As Boolean
        Get
            Return _isacted
        End Get
        Set(ByVal value As Boolean)
            _isacted = value
        End Set
    End Property

    Public ReadOnly Property Phases() As List(Of Integer)
        Get
            Return _phases
        End Get
    End Property

    Public Property Dexterity() As Integer
        Get
            Return _dexterity
        End Get
        Set(ByVal value As Integer)
            If Me.Dexterity <> value Then
                _dexterity = value
                RaiseEvent DexterityChanged(Me, Me.Dexterity)
            End If
        End Set
    End Property

    Public Property NPC() As Boolean
        Get
            Return _npc
        End Get
        Set(ByVal value As Boolean)
            _npc = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Property Speed() As Double
        Get
            Return _speed
        End Get
        Set(ByVal value As Double)
            If Me.Speed <> value Then
                _speed = value
                If Me.Speed > 0 Then
                    _phases = GetPhases(Me.Speed)
                End If
                RaiseEvent SpeedChanged(Me, Me.Speed)
            End If
        End Set
    End Property

    Public Property Endurance() As Integer
        Get
            Return _endurance
        End Get
        Set(ByVal value As Integer)
            If Me.Endurance <> value Then
                _endurance = value
                If Me.Endurance < Me.CurrentEndurance Then
                    Me.CurrentEndurance = value
                End If
                RaiseEvent EnduranceChanged(Me, Me.Endurance)
            End If
        End Set
    End Property

    Public Property Recovery() As Integer
        Get
            Return _recovery
        End Get
        Set(ByVal value As Integer)
            If Me.Recovery <> value Then
                _recovery = value
                RaiseEvent RecoveryChanged(Me, Me.Recovery)
            End If
        End Set
    End Property

    Public Property Body() As Integer
        Get
            Return _body
        End Get
        Set(ByVal value As Integer)
            If Me.Body <> value Then
                _body = value
                If Me.Body < Me.CurrentBody Then
                    Me.CurrentBody = value
                End If
                RaiseEvent BodyChanged(Me, Me.Body)
            End If
        End Set
    End Property

    Public Property Stun() As Integer
        Get
            Return _stun
        End Get
        Set(ByVal value As Integer)
            If Me.Stun <> value Then
                _stun = value
                If Me.Stun < Me.CurrentStun Then
                    Me.CurrentStun = value
                End If
                RaiseEvent StunChanged(Me, Me.Stun)
            End If
        End Set
    End Property

    Public Property Ego() As Integer
        Get
            Return _ego
        End Get
        Set(ByVal value As Integer)
            _ego = value
        End Set
    End Property

    Public Property OCV() As Integer
        Get
            Return _ocv
        End Get
        Set(ByVal value As Integer)
            _ocv = value
        End Set
    End Property

    Public Property DCV() As Integer
        Get
            Return _dcv
        End Get
        Set(ByVal value As Integer)
            _dcv = value
        End Set
    End Property

    Public Property mOCV() As Integer
        Get
            Return _mocv
        End Get
        Set(ByVal value As Integer)
            _mocv = value
        End Set
    End Property

    Public Property mDCV() As Integer
        Get
            Return _mdcv
        End Get
        Set(ByVal value As Integer)
            _mdcv = value
        End Set
    End Property

    Public Property PD() As Integer
        Get
            Return _pd
        End Get
        Set(ByVal value As Integer)
            _pd = value
        End Set
    End Property

    Public Property ED() As Integer
        Get
            Return _ed
        End Get
        Set(ByVal value As Integer)
            _ed = value
        End Set
    End Property

    Public Property MD() As Integer
        Get
            Return _md
        End Get
        Set(ByVal value As Integer)
            _md = value
        End Set
    End Property

    Public Property rPD() As Integer
        Get
            Return _rpd
        End Get
        Set(ByVal value As Integer)
            _rpd = value
        End Set
    End Property

    Public Property rED() As Integer
        Get
            Return _red
        End Get
        Set(ByVal value As Integer)
            _red = value
        End Set
    End Property

    Public Function GetPhases(ByVal speed As Double) As List(Of Integer)
        Dim ret As New List(Of Integer)
        For i As Integer = 1 To 12
            ret.Add(0)
        Next
        Select Case speed
            Case Is < 2
                ret(0) = 7
                Return ret
            Case Is < 3
                ret(0) = 6
                ret(1) = 12
            Case Is < 4
                ret(0) = 4
                ret(1) = 8
                ret(2) = 12
                Return ret
            Case Is < 5
                ret(0) = 3
                ret(1) = 6
                ret(2) = 9
                ret(3) = 12
                Return ret
            Case Is < 6
                ret(0) = 3
                ret(1) = 5
                ret(2) = 8
                ret(3) = 10
                ret(4) = 12
            Case Is < 7
                ret(0) = 2
                ret(1) = 4
                ret(2) = 6
                ret(3) = 8
                ret(4) = 10
                ret(5) = 12
            Case Is < 8
                ret(0) = 2
                ret(1) = 4
                ret(2) = 6
                ret(3) = 7
                ret(4) = 8
                ret(5) = 10
                ret(6) = 12
            Case Is < 9
                ret(0) = 2
                ret(1) = 3
                ret(2) = 5
                ret(3) = 6
                ret(4) = 8
                ret(5) = 9
                ret(6) = 11
                ret(7) = 12
            Case Is < 10
                ret(0) = 2
                ret(1) = 3
                ret(2) = 4
                ret(3) = 6
                ret(4) = 7
                ret(5) = 8
                ret(6) = 10
                ret(7) = 11
                ret(8) = 12
            Case Is < 11
                ret(0) = 2
                ret(1) = 3
                ret(2) = 4
                ret(3) = 5
                ret(4) = 6
                ret(5) = 8
                ret(6) = 9
                ret(7) = 10
                ret(8) = 11
                ret(9) = 12
            Case Is < 12
                ret(0) = 2
                ret(1) = 3
                ret(2) = 4
                ret(3) = 5
                ret(4) = 6
                ret(5) = 7
                ret(6) = 8
                ret(7) = 9
                ret(8) = 10
                ret(9) = 11
                ret(10) = 12
            Case 12
                ret(0) = 1
                ret(1) = 2
                ret(2) = 3
                ret(3) = 4
                ret(4) = 5
                ret(5) = 6
                ret(6) = 7
                ret(7) = 8
                ret(8) = 9
                ret(9) = 10
                ret(10) = 11
                ret(11) = 12
        End Select
        Return ret
    End Function
End Class
